import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
import { ButtonGroupConfig, ButtonConfig } from '../core';

@Injectable()
export class ListBottonsConfigService {
  public buttonsConfig: ButtonGroupConfig[];

  private new$ = new Subject();
  public newButton: ButtonConfig = {
    name: '新增',
    fn: () => this.new$.next(),
    visable: true,
    enabled: true,
  };
  public get onNewClick() {
    return this.new$.asObservable();
  }

  private delete$ = new Subject();
  public deleteButton: ButtonConfig = {
    name: '删除',
    fn: () => this.delete$.next(),
    visable: true,
    enabled: true,
  };
  public get onDeleteClick() {
    return this.delete$.asObservable();
  }

  private submit$ = new Subject();
  public submitButton: ButtonConfig = {
    name: '提交',
    fn: () => this.submit$.next(),
    visable: true,
    enabled: true,
  };
  public get onSubmitClick() {
    return this.submit$.asObservable();
  }

  private back$ = new Subject();
  public backButton: ButtonConfig = {
    name: '撤销',
    fn: () => this.back$.next(),
    visable: true,
    enabled: true,
  };
  public get onBackClick() {
    return this.back$.asObservable();
  }

  private approve$ = new Subject();
  public approveButton: ButtonConfig = {
    name: '审核',
    fn: () => this.approve$.next(),
    visable: true,
    enabled: true,
  };
  public get onApproveClick() {
    return this.approve$.asObservable();
  }

  private unapprove$ = new Subject();
  public unapproveButton: ButtonConfig = {
    name: '弃审',
    fn: () => this.unapprove$.next(),
    visable: true,
    enabled: true,
  };
  public get onUnapproveClick() {
    return this.unapprove$.asObservable();
  }

  private export$ = new Subject();
  public exportButton: ButtonConfig = {
    name: '导出',
    fn: () => this.export$.next(),
    visable: true,
    enabled: true,
  };
  public get onExportClick() {
    return this.export$.asObservable();
  }

  private print$ = new Subject();
  public printButton: ButtonConfig = {
    name: '打印',
    fn: () => this.print$.next(),
    visable: true,
    enabled: true,
  };
  public get onPrintClick() {
    return this.print$.asObservable();
  }

  private refresh$ = new Subject();
  public refreshButton: ButtonConfig = {
    name: '刷新',
    fn: () => this.refresh$.next(),
    visable: true,
    enabled: true,
  };
  public get onRefreshClick() {
    return this.refresh$.asObservable();
  }

  public operateButtonGroup: ButtonGroupConfig;
  public approveButtonGroup: ButtonGroupConfig;
  public outputButtonGroup: ButtonGroupConfig;
  public refreshButtonGroup: ButtonGroupConfig;

  constructor() {
    this.operateButtonGroup = {
      buttonGroup: [this.newButton, this.deleteButton],
      visable: true,
    };

    this.approveButtonGroup = {
      buttonGroup: [this.submitButton, this.backButton, this.approveButton, this.unapproveButton],
      visable: true,
    };

    this.outputButtonGroup = {
      buttonGroup: [this.exportButton, this.printButton],
      visable: true,
    };

    this.refreshButtonGroup = {
      buttonGroup: [this.refreshButton],
      visable: true,
    };

    this.buttonsConfig = [
      this.operateButtonGroup,
      this.approveButtonGroup,
      this.outputButtonGroup,
      this.refreshButtonGroup,
    ];
  }
}
